package com.emergency.controller;

import com.emergency.data.vo.RescueTeamCountVO;
import com.emergency.http.WrapMapper;
import com.emergency.http.Wrapper;
import com.emergency.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Validated
@RestController
@RequestMapping("/resource")
@Api(tags = "应急资源API")
public class ResourceController {

    @Resource
    private LinkmanPointService linkmanPointService;

    @Resource
    private RescueTeamService rescueTeamService;

    @Resource
    private SettlementPointService settlementPointService;

    @Resource
    private AddressBookService addressBookService;

    @Resource
    private StreetService streetService;

    @Resource
    private EmergencySuppliesPointService emergencySuppliesPointService;

    /**
     * 负责人联络点主页数据列表
     *
     * @param streetId  街道ID
     * @param villageId 村社区ID
     * @param phone     联系电话
     * @param name      姓名
     * @param type      查询类型 1-乡镇/街道 2-村/社区
     * @return Wrapper
     */
    @ApiOperation("负责人联络点主页数据列表")
    @GetMapping("/getLinkmanPointList")
    public Wrapper<?> getLinkmanList(
            @ApiParam("街道ID") @RequestParam(required = false) Integer streetId,
            @ApiParam("村社区ID") @RequestParam(required = false) Integer villageId,
            @ApiParam("查询类型 1-乡镇/街道 2-村/社区") @RequestParam(required = false) Integer type,
            @ApiParam("联系电话") @RequestParam(required = false) String phone,
            @ApiParam("姓名") @RequestParam(required = false) String name) {
        return WrapMapper.ok(linkmanPointService.getLinkmanList(streetId, villageId, phone, name, type));
    }

    /**
     * 负责人联络点详情
     *
     * @param id 负责人联络点ID
     * @return Wrapper
     */
    @ApiOperation("负责人联络点详情")
    @GetMapping("/getLinkmanPointDetail")
    public Wrapper<?> getLinkmanPointDetail(@ApiParam("负责人联络点ID") @RequestParam Long id) {
        return WrapMapper.ok(linkmanPointService.getLinkmanPointDetail(id));
    }

    /**
     * 救援队伍列表
     *
     * @param streetId 街道ID
     * @param id       队伍类型ID
     * @param teamName 队伍名称
     * @return Wrapper
     */
    @ApiOperation("救援队伍列表")
    @GetMapping("/getRescueTeamList")
    public Wrapper<?> getRescueTeamList(@ApiParam("街道ID") @RequestParam(required = false) Long streetId,
                                        @ApiParam("队伍类型ID") @RequestParam(required = false) Long id,
                                        @ApiParam("队伍名称") @RequestParam(required = false) String teamName) {
        return WrapMapper.ok(rescueTeamService.getRescueTeamList(streetId, id, teamName));
    }

    /**
     * 救援队伍详情
     *
     * @param id 队伍ID
     * @return Wrapper
     */
    @ApiOperation("救援队伍详情")
    @GetMapping("/getRescueTeamDetail")
    public Wrapper<?> getRescueTeamDetail(@ApiParam("队伍ID") @NotNull(message = "id 不能为空") @RequestParam Long id) {
        return WrapMapper.ok(rescueTeamService.getRescueTeamDetail(id));
    }

    /**
     * 应急资源列表
     *
     * @return Wrapper
     */
    @ApiOperation("应急资源列表")
    @GetMapping("/getResourceList")
    public Wrapper<?> getResourceList() {
        Map<String, Object> map = streetService.getResourceList();
        return WrapMapper.ok(map);
    }

    /**
     * 数据资源统计
     *
     * @return Wrapper
     */
    @ApiOperation("数据资源统计")
    @GetMapping("/dataStatistics")
    public Wrapper<?> dataStatistics() {
        Map<String, Object> map = streetService.dataStatistics();
        return WrapMapper.ok(map);
    }

    /**
     * 救援队伍统计
     *
     * @return Wrapper
     */
    @ApiOperation("救援队伍统计")
    @GetMapping("/rescueTeamStatistics")
    public Wrapper<?> rescueTeamStatistics() {
        Map<String, Object> map = new HashMap<>();
        List<RescueTeamCountVO> dataList = rescueTeamService.rescueTeamStatistics();
        map.put("dataList", dataList);
        return WrapMapper.ok(map);
    }

    /**
     * 通讯录列表
     *
     * @param name      姓名
     * @param deptId    部门ID
     * @param streetId  街道ID
     * @param villageId 村社区ID
     * @return Wrapper
     */
    @ApiOperation("通讯录列表")
    @PostMapping("/getAddressBookList")
    public Wrapper<?> getAddressBookList(@ApiParam("当前页数") @RequestParam(required = false) Integer page,
                                         @ApiParam("每页条数") @RequestParam(required = false, defaultValue = "10") Integer size,
                                         @ApiParam("姓名") @RequestParam(required = false) String name,
                                         @ApiParam("查询类型 1-乡镇/街道 2-村/社区") @RequestParam(required = false) Integer type,
                                         @ApiParam("部门ID") @RequestParam(required = false) Integer deptId,
                                         @ApiParam("街道ID") @RequestParam(required = false) Integer streetId,
                                         @ApiParam("村社区ID") @RequestParam(required = false) Integer villageId) {
        return WrapMapper.ok(addressBookService.getAddressBookList(page, size, name, deptId, streetId, villageId, type));
    }

    /**
     * 避灾安置点列表
     *
     * @param level    级别
     * @param area     场所面积
     * @param capacity 容纳人数
     * @param siteName 场所名称
     * @return Wrapper
     */
    @ApiOperation("避灾安置点列表")
    @GetMapping("/getSettlementPointList")
    public Wrapper<?> getSettlementPointList(@ApiParam("区域") @RequestParam(required = false) Integer streetId,
                                             @ApiParam("级别") @RequestParam(required = false) String level,
                                             @ApiParam("场所面积") @RequestParam(required = false) String area,
                                             @ApiParam("容纳人数") @RequestParam(required = false) Integer capacity,
                                             @ApiParam("场所名称") @RequestParam(required = false) String siteName) {
        return WrapMapper.ok(settlementPointService.getSettlementPointList(streetId, level, area, capacity, siteName));
    }

    /**
     * 避灾安置点详情
     *
     * @param id 安置点ID
     * @return Wrapper
     */
    @ApiOperation("避灾安置点详情")
    @GetMapping("/getSettlementPointDetail")
    public Wrapper<?> getSettlementPointDetail(@ApiParam("安置点ID") @NotNull(message = "id 不能为空") @RequestParam Long id) {
        return WrapMapper.ok(settlementPointService.getSettlementPointDetail(id));
    }

    /**
     * 应急物资点列表
     *
     * @param streetId  乡镇/街道ID
     * @param villageId 村/社区ID
     * @param name      输入搜索的地点名称
     * @param type      查询类型 1-乡镇/街道 2-村/社区
     * @return Wrapper
     */
    @ApiOperation("应急物资点列表")
    @GetMapping("/getEmergencySuppliesPointList")
    public Wrapper<?> getEmergencySuppliesPointList(@ApiParam("乡镇/街道ID") @RequestParam(required = false) Long streetId,
                                                    @ApiParam("村/社区ID") @RequestParam(required = false) Long villageId,
                                                    @ApiParam("查询类型 1-乡镇/街道 2-村/社区") @RequestParam(required = false) Integer type,
                                                    @ApiParam("输入搜索的地点名称") @RequestParam(required = false) String name) {
        return WrapMapper.ok(emergencySuppliesPointService.getEmergencySuppliesPointList(streetId, villageId, name, type));
    }

    /**
     * 应急物资点详情
     *
     * @param id 应急物资点ID
     * @return Wrapper
     */
    @ApiOperation("应急物资点详情")
    @GetMapping("/getEmergencySuppliesPointDetail")
    public Wrapper<?> getEmergencySuppliesPointDetail(@ApiParam("应急物资点ID") @NotNull(message = "id 不能为空") @RequestParam Long id) {
        return WrapMapper.ok(emergencySuppliesPointService.getEmergencySuppliesPointDetail(id));
    }
}
